<?php
$g_name=isset($_GET['g_name'])?$_GET['g_name']:"";

$where="1";
if(!empty($g_name))
{
    $where.=" and g_name like '%$g_name%'";
}
$page=isset($_GET['page'])?$_GET['page']:1;
$size=isset($_GET['limit'])?$_GET['limit']:3;

$redis=new Redis();
$redis->connect("127.0.0.1",6379);
if($redis->Hexists('loop',"page$page") && $where=="1")
{
    $redis->hGet('loop',"page$page");
}

include "show2.php";
$dbh = new BDO('127.0.0.1', 'root', 'root');
$count=$dbh->getNamber("games",$where);
$limit=($page-1)*$size;
$data=$dbh->getAll("games",$where,$limit,$size);
if(!$data)
{
    $arr['code']=1;
    $arr['msg']="失败";
    $arr['data']="";
    $arr['count']="";
    echo json_encode($arr);
}
$arr['code']=0;
$arr['msg']="成功";
$arr['data']=$data;
$arr['count']=$count;
echo json_encode($arr);

if($where=="1")
{
    $redis->hSet('loop',"page$page",json_encode($data));
}

?>